import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:glass_kit/glass_kit.dart';
import 'package:todo_project/color.dart';
import 'package:todo_project/generated/assets.dart';

class HomeDrawer extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _HomeDrawerState();
}

class _HomeDrawerState extends State<HomeDrawer> {
  List<Map> titleNameList = [
    {"icon": Assets.assetsIcToday, "name": "今日"},
    {"icon": Assets.assetsIcToday, "name": "重要"},
    {"icon": Assets.assetsIcToday, "name": "周期"}
  ];
  List<String> aboutNameList = ["通知", "设置", "周期"];

  @override
  Widget build(BuildContext context) {
    return GlassContainer(
      margin: EdgeInsets.only(
          top: kToolbarHeight + MediaQuery.of(context).padding.top),
      height: double.infinity,
      width: 304.0,
      blur: 5,
      color: Colors.white38,
      borderWidth: 1,
      borderGradient: LinearGradient(
        colors: [
          Colors.white.withOpacity(0.20),
          Colors.white.withOpacity(0.1),
          Colors.white.withOpacity(0.05),
          Colors.white.withOpacity(0.3)
        ],
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
        stops: const [0.0, 0.2, 0.60, 1.0],
      ),
      borderColor: Colors.transparent,
      borderRadius: BorderRadius.only(topRight: Radius.circular(20.w)),
      child: Column(
        children: [
          Container(
            padding: EdgeInsets.symmetric(vertical: 20.w, horizontal: 12.w),
          ),
          Expanded(
            child: CustomScrollView(
              slivers: [
                SliverToBoxAdapter(
                  child: Padding(
                      child: Text(
                        "我的任务",
                        style: TextStyle(
                            fontSize: 18.sp,
                            color: AppColor.textColor,
                            fontWeight: FontWeight.bold),
                      ),
                      padding: EdgeInsets.symmetric(
                          vertical: 20.w, horizontal: 12.w)),
                ),
                SliverList(
                    delegate: SliverChildBuilderDelegate(
                        (ctx, index) => MaterialButton(
                              textColor: AppColor.textColor,
                              padding: EdgeInsets.symmetric(horizontal: 20.w),
                              child: Container(
                                padding: EdgeInsets.symmetric(vertical: 10.w),
                                child: Row(
                                  children: [
                                    SvgPicture.asset(
                                      titleNameList[index]["icon"],
                                      height: 20.w,
                                      color: AppColor.textColor,
                                      width: 20.w,
                                    ),
                                    Expanded(child: Container()),
                                    Text(
                                      titleNameList[index]["name"],
                                      style: TextStyle(fontSize: 16.sp),
                                    )
                                  ],
                                ),
                              ),
                              onPressed: () {
                                Navigator.pop(context);
                              },
                              materialTapTargetSize:
                                  MaterialTapTargetSize.shrinkWrap,
                            ),
                        childCount: titleNameList.length)),
                SliverToBoxAdapter(
                  child: MaterialButton(
                    textColor: AppColor.textColor,
                    padding: EdgeInsets.symmetric(horizontal: 20.w),
                    child: Container(
                      padding: EdgeInsets.symmetric(vertical: 10.w),
                      child: Row(
                        children: [
                          Text(
                            "通知",
                            style: TextStyle(fontSize: 16.sp),
                          ),
                          Expanded(child: Container()),
                          CupertinoSwitch(
                            value: false,
                            onChanged: (chekc) {},
                          ),
                          const Icon(
                            Icons.chevron_right,
                            color: AppColor.textColor,
                          )
                        ],
                      ),
                    ),
                    onPressed: () {
                      Navigator.pop(context);
                    },
                    materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                  ),
                ),
                buildSettingItem(context, "意见反馈", () {}),
                buildSettingItem(context, "个人信息与隐私保护", () {}),
                buildSettingItem(context, "关于", () {})
              ],
            ),
          ),
        ],
      ),
    );
  }

  SliverToBoxAdapter buildSettingItem(
      BuildContext context, String title, Function() onPress) {
    return SliverToBoxAdapter(
      child: MaterialButton(
        textColor: AppColor.textColor,
        padding: EdgeInsets.symmetric(horizontal: 20.w),
        child: Container(
          padding: EdgeInsets.symmetric(
            vertical: 10.w,
          ),
          child: Row(
            children: [
              Text(
                title,
                style: TextStyle(fontSize: 16.sp),
              ),
              Expanded(child: Container()),
              const Icon(
                Icons.chevron_right,
                color: AppColor.textColor,
              )
            ],
          ),
        ),
        onPressed: onPress,
        materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
      ),
    );
  }
}
